<script type="text/javascript">     
$(document).ready(function(){

    // check for first change in form
    <? if($this->input->post("submit_action")!==FALSE){ ?>
        var hasChanged = true;                 
    <? } else { ?>
        var hasChanged = false;                
        $("input:submit").addClass("disabled");
    <? } ?>
    $("input,textarea").live("change", function(){
        if(hasChanged == false){
            hasChanged = true;
            $("input:submit").removeClass("disabled");
        }
    });

    //cancel button
    $(".cancel").click(function(){
        if (hasChanged != false)
            if (!confirm("If you leave this page now, you will loose the changes you've just made.\n\nProceed anyway?\n")) return false;
            window.location.href='<?=site_url("admin/exhibitions")?>';
        return false;
    });

    var image = $(".ImageManager_Widget img");
    var image_input = $(".ImageManager_Widget input.img_path");
    var remove_button = $(".ImageManager_Widget .delete_image");

    if($(image_input).val() == ""){
        $(image).hide();
        $(remove_button).hide();
    }

    function ImageManagerCallback(img_path){

        display_path = "<?=base_url().UPLOADS_FOLDER.EXHIBITIONS_IMG_FOLDER;?>"+img_path;
        $(image).attr("src", display_path).fadeIn();
        $(image_input).val(img_path).change(); 
        $(remove_button).fadeIn();

    }

    // bind triggers that open the ImageManager
    $(".open_image_manager").live("click", function () {       
        mcImageManager.open('','','',
            function(img_path){
                ImageManagerCallback(img_path);
            },
            {
				rootpath : '{0}/<?=EXHIBITIONS_IMG_FOLDER?>',
				document_base_url : '<?=base_url().UPLOADS_FOLDER.EXHIBITIONS_IMG_FOLDER?>',
				relative_urls : true		
			}
        );
        return false;
    }); 

    // delete parent selector that matches the rel attribute
    $(remove_button).click(function() {  
        $(image).hide();
        $(image_input).val("").change();
        $(remove_button).hide();     
        return false;
    });   

       
                  
});  
       
</script>

<div id="content">

<? if($this->input->post("submit_action") !== FALSE){ ?>
    <div class="response"><?=validation_errors()?></div>                
<? } ?>

    <form action="" method="post" id="exhibitions_form">

    <div class="float_block_right">
        <a href="#" class="button cancel">CANCEL</a>
        <a href="<?=site_url('admin/exhibitions/preview')?>" class="button" rel="preview">PREVIEW</a>
        <input type="submit" class="button " value="SAVE CHANGES">  
    </div>



    <? if ($action=='update') { ?>
        <h1>Edit Exhibition</h1>
    <? } else { ?>
        <h1>Add New Exhibition</h1>
    <? } ?>
          
    <div class="content_block">

        <div style="float:right; tex-align:left">
        <h4>Date end</h4>
        <input name="date" type="text" class="text_input datepicker" maxlength="10" value="<?=set_value('date2', $item['Date2_Exhibitions'])?>" style="width:187px" />
        </div>

        <h4>Date start</h4>
        <input name="date" type="text" class="text_input datepicker" maxlength="10" value="<?=set_value('date', $item['Date_Exhibitions'])?>" style="width:187px" />

    </div>
                
    <div class="content_block">
        <h4>Title</h4>
        <input name="title" type="text" class="text_input" maxlength="250" value="<?=set_value('title', $item['Title_Exhibitions'])?>" />
    </div>

    <div class="content_block">
        <h4>Introduction</h4>
        <textarea name="introduction" class="tinymceEditor_no_paragraph"><?=set_value('introduction', $item['Introduction_Exhibitions'])?></textarea>
    </div>

    <div class="content_block">
        <h4>Description</h4>
        <textarea name="description" class="tinymceEditor_force_paragraph"><?=set_value('description', $item['Description_Exhibitions'])?></textarea>
    </div>

    <div id="image" class="content_block ImageManager_Widget">
        <h4>Image</h4>
        <img src="<?=base_url().UPLOADS_FOLDER.EXHIBITIONS_IMG_FOLDER.set_value('image', $item['Image_Exhibitions'])?>" style="display:block" />
        <a class="open_image_manager button" href="#">SELECT IMAGE</a>
        <a class="delete_image button" title="You're about to remove this image. Confirm?" rel="div" href="#">REMOVE</a> 
        <input type="hidden" name="image" class="img_path" value="<?=set_value('image', $item['Image_Exhibitions'])?>" />    
    </div>    
                     
               
    <input type="hidden" name="submit_action" value="<?=$action?>" />
    <input type="hidden" name="id" value="<?=$item['id_Exhibitions']?>" />
    <input type="hidden" name="token" value="<?=$token?>" />

    <div class="float_block_right">
        <a href="#" class="button cancel">CANCEL</a>
        <a href="<?=site_url('admin/exhibitions/preview')?>" class="button" rel="preview">PREVIEW</a>
        <input type="submit" class="button " value="SAVE CHANGES">  
    </div>

    </form>

</div>